package com.haogu.controller;

import com.haogu.entity.Employee;
import com.haogu.entity.User;
import com.haogu.service.EmployeeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;
    /**
     * 去展示页面
     */
    @RequestMapping("/toListEmployee")
    public String toListEmployee(){
        return "employee/list_employee";
    }
    /**
     * 展示员工数据
     */
    @RequestMapping("/listEmployee")
    @ResponseBody
    public Map listEmployee(Integer page,Integer rows,String name){
        return employeeService.listEmployee(page,rows,name);
    }

    /**
     * 去添加页面
     */
    @RequestMapping("/toAddEmployee")
    public String toAddEmployee(Model model){
        employeeService.toAddEmployee(model);
        return "employee/add_employee";
    }
    //添加
    @RequestMapping("/addEmployee")
    @ResponseBody
    public Map addEmployee(Employee employee,HttpSession session){
        return employeeService.addEmployee(employee,(User)session.getAttribute("user"));
    }

    /**
     * 去修改页面
     */
    @RequestMapping("/toEditEmployee")
    public String toEditEmployee(Integer id,Model model){
        employeeService.toUpdateEmployee(id,model);
        return "employee/edit_employee";
    }
    @RequestMapping("/updateEmployee")
    @ResponseBody
    public Map updateEmployee(Employee employee,HttpSession session){
        return employeeService.updateEmployee(employee,(User) session.getAttribute("user"));
    }
    /**
     * 删除employee
     */
    @RequestMapping("deleteEmployee")
    @ResponseBody
    public Map deleteEmployee(String ids){
        return employeeService.deleteEmployee(ids);
    }
}
